<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<LINK REL=STYLESHEET TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
<META NAME="GENERATOR" CONTENT="Java2HTML Version 1.5">
<TITLE>czestmyr.jjsched.Macros (Java2HTML)</TITLE>
</HEAD>
<BODY><TABLE id="Header" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2" width="33%">&nbsp;</td>
<td align="center" colspan="2" width="33%">
<font size="4">Macros.java</font>
</td>
<td align="right" colspan="2" width="33%">&nbsp;</td>
</tr>
</TABLE>
<pre ID="Classes">
<A NAME="1"></A><FONT ID="MultiLineComment">/*  This file is a part of JJSched source code
<A NAME="2"></A>    JJSched - Java Jabber Scheduler - a simple Jabber scheduling application
<A NAME="3"></A>    Copyright (C) 2008 Cestmir "CZestmyr" Houska
<A NAME="4"></A>
<A NAME="5"></A>    This program is free software: you can redistribute it and/or modify
<A NAME="6"></A>    it under the terms of the GNU General Public License as published by
<A NAME="7"></A>    the Free Software Foundation, either version 3 of the License, or
<A NAME="8"></A>    (at your option) any later version.
<A NAME="9"></A>
<A NAME="10"></A>    This program is distributed in the hope that it will be useful,
<A NAME="11"></A>    but WITHOUT ANY WARRANTY; without even the implied warranty of
<A NAME="12"></A>    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<A NAME="13"></A>    GNU General Public License for more details.
<A NAME="14"></A>
<A NAME="15"></A>    You should have received a copy of the GNU General Public License
<A NAME="16"></A>    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt; */</FONT>
<A NAME="17"></A>
<A NAME="18"></A><FONT ID="Package">package</FONT> czestmyr.jjsched;
<A NAME="19"></A>
<A NAME="20"></A><FONT ID="Import">import</FONT> java.util.*;
<A NAME="21"></A>
<A NAME="22"></A><FONT ID="FormalComment">/**
<A NAME="23"></A> * Serves for holding definitions of all defined global macros.
<A NAME="24"></A> * A macro is a substitution rule for simplifying the jjsched command 
<A NAME="25"></A> * syntax. A macro has its keyword and body. When the substitution takes
<A NAME="26"></A> * place, each occurence of the keyword token is replaced by the list
<A NAME="27"></A> * of tokens in the body. The substitution is non-recursive - e.g. the
<A NAME="28"></A> * macro body cannot contain keywords of other macros.
<A NAME="29"></A> */</FONT>
<A NAME="30"></A><FONT ID="Public">public</FONT> <FONT ID="Class">class</FONT> Macros{
<A NAME="31"></A>    <FONT ID="FormalComment">/**
<A NAME="32"></A>     * Default constructor
<A NAME="33"></A>     */</FONT>
<A NAME="34"></A>    Macros(){
<A NAME="35"></A>        macro_table = <FONT ID="New">new</FONT> HashMap&lt;String, Vector&lt;String&gt;&gt;();
<A NAME="36"></A>    }
<A NAME="37"></A>
<A NAME="38"></A>    <FONT ID="FormalComment">/**
<A NAME="39"></A>     * Determines whether a token is a macro keyword.
<A NAME="40"></A>     *
<A NAME="41"></A>     * @param   token   the token in question
<A NAME="42"></A>     * @return      true if the token is a keyword of a macro, false otherwise
<A NAME="43"></A>     */</FONT>
<A NAME="44"></A>    <FONT ID="Boolean">boolean</FONT> isMacro(String token){
<A NAME="45"></A>        <FONT ID="If">if</FONT> (macro_table.containsKey(token)) <FONT ID="Return">return</FONT> <FONT ID="True">true</FONT>;
<A NAME="46"></A>        <FONT ID="Else">else</FONT> <FONT ID="Return">return</FONT> <FONT ID="False">false</FONT>;
<A NAME="47"></A>    }
<A NAME="48"></A>
<A NAME="49"></A>    <FONT ID="FormalComment">/**
<A NAME="50"></A>     * Returns body of macro with the keyword token.
<A NAME="51"></A>     *
<A NAME="52"></A>     * @param   token   the keyword token
<A NAME="53"></A>     * @return      body of macro with the keyword token if the macro is defined,
<A NAME="54"></A>     *          null otherwise
<A NAME="55"></A>     */</FONT>
<A NAME="56"></A>    Vector&lt;String&gt; getMacroBody(String token){
<A NAME="57"></A>        Vector&lt;String&gt; ret;
<A NAME="58"></A>        <FONT ID="Try">try</FONT> {
<A NAME="59"></A>            ret = macro_table.get(token);
<A NAME="60"></A>        } <FONT ID="Catch">catch</FONT> (Exception e) {
<A NAME="61"></A>            ret = <FONT ID="Null">null</FONT>;
<A NAME="62"></A>        }
<A NAME="63"></A>        <FONT ID="Return">return</FONT> ret;
<A NAME="64"></A>    }
<A NAME="65"></A>
<A NAME="66"></A>    <FONT ID="FormalComment">/**
<A NAME="67"></A>     * Creates a new macro with the specified keyword and body.
<A NAME="68"></A>     * Replaces the macro if it already exists with the given keyword.
<A NAME="69"></A>     *
<A NAME="70"></A>     * @param   keyword keyword of the new macro
<A NAME="71"></A>     * @param   body    iterator on the list containing body of the new macro
<A NAME="72"></A>     */</FONT>
<A NAME="73"></A>    <FONT ID="Void">void</FONT> newMacro(String keyword, Iterator&lt;String&gt; body){
<A NAME="74"></A>        Vector&lt;String&gt; macro = <FONT ID="New">new</FONT> Vector&lt;String&gt;();
<A NAME="75"></A>
<A NAME="76"></A>        <FONT ID="While">while</FONT> (body.hasNext()){
<A NAME="77"></A>            macro.add(body.next());
<A NAME="78"></A>        }
<A NAME="79"></A>
<A NAME="80"></A>        macro_table.put(keyword, macro);
<A NAME="81"></A>    }
<A NAME="82"></A>
<A NAME="83"></A>    <FONT ID="FormalComment">/**
<A NAME="84"></A>     * Returns an iterator to the macro table
<A NAME="85"></A>     */</FONT>
<A NAME="86"></A>    Iterator getMacrosIterator(){
<A NAME="87"></A>        <FONT ID="Return">return</FONT> macro_table.entrySet().iterator();
<A NAME="88"></A>    }
<A NAME="89"></A>
<A NAME="90"></A>    <FONT ID="FormalComment">/**
<A NAME="91"></A>     * The data structure used to hold global macro definitions.
<A NAME="92"></A>     */</FONT>
<A NAME="93"></A>    HashMap&lt;String, Vector&lt;String&gt;&gt; macro_table;
<A NAME="94"></A>}</pre>
</BODY>
</HTML>